# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=conversion-bytestring
pkgname=haskell-conversion-bytestring
pkgver=1.0.1.1
pkgrel=1
pkgdesc="Conversion instances for the bytestring library"
url="https://github.com/nikita-volkov/conversion-bytestring"
license=('MIT')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base-prelude' 'haskell-conversion')
makedepends=('ghc' 'uusi')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('12945dbdeea1c3c98f060b2723df989c9f03c6d94afe74d82c3f81b3bf6b88860a6a0e2312f6a8d8fe37eabe35e9ac100b168ea26ad0209ee872f65f6a835aa3')

prepare() {
    cd $_hkgname-$pkgver
    gen-setup
}

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
